import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:text_world/global.dart';
import 'package:text_world/iconfont.dart';
import 'package:text_world/main_manager.dart';
import 'package:text_world/pages/like.dart';
import 'package:text_world/pages/yiju.dart';
import 'package:text_world/pages/yiwen.dart';

void main() {
  Provider.debugCheckInvalidValueType = null;
  WidgetsFlutterBinding.ensureInitialized();
  runApp(
    MultiProvider(
      child: MyApp(),
      providers: [
        ChangeNotifierProvider.value(value: MainManager()..init()),
      ],
    ),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '文字世界',
      theme: ThemeData(
        brightness: Brightness.light,
        primaryColor: Global.cardBackgroundColor,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _currentIndex = 0;
  List<Widget> pages = [YijuPage(), YiWenPage(), LikePage()];

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        elevation: 0,
        items: [
          BottomNavigationBarItem(
            icon: Icon(
              IconFont.yuan1,
              size: 17,
              color: Global.primaryColor.withOpacity(0.2),
            ),
            activeIcon: Icon(
              IconFont.yuan,
              size: 17,
              color: Global.primaryColor,
            ),
            title: Text(
              '一句',
              style: TextStyle(
                color: Global.primaryColor,
                fontSize: 13,
                fontFamily: 'fangzhengkai',
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              IconFont.fangkuai,
              size: 17,
              color: Global.primaryColor.withOpacity(0.2),
            ),
            activeIcon: Icon(
              IconFont.fangkuai1,
              size: 17,
              color: Global.primaryColor,
            ),
            title: Text(
              '一文',
              style: TextStyle(
                color: Global.primaryColor,
                fontSize: 13,
                fontFamily: 'fangzhengkai',
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.favorite_border,
              size: 17,
              color: Global.primaryColor.withOpacity(0.2),
            ),
            activeIcon: Icon(
              Icons.favorite,
              size: 17,
              color: Global.likeColor,
            ),
            title: Text(
              '喜欢',
              style: TextStyle(
                color: Global.primaryColor,
                fontSize: 13,
                fontFamily: 'fangzhengkai',
              ),
            ),
          ),
        ],
        currentIndex: _currentIndex,
        onTap: (int index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }
}
